package com.igoal.dto;

import java.util.Date;

import org.tuckey.web.filters.urlrewrite.utils.StringUtils;

import com.igoal.entity.UserGoalTask;
import com.igoal.utils.CalendarUtils;
import com.igoal.utils.SynchronizeAttributeWithOther;
import com.igoal.utils.SynchronizeDirection;

public class UserGoalTaskDTO extends BaseDTO<UserGoalTask> {
	private Long phaseId;
	private Long goalId;
	private Long userId;
	private String taskName;
	private Integer percentMeasure;
	private String deadLine;
	private Boolean finished;
	private Integer index;

	public Long getGoalId() {
		return goalId;
	}

	public void setGoalId(Long goalId) {
		this.goalId = goalId;
	}

	public Long getPhaseId() {
		return phaseId;
	}

	public void setPhaseId(Long phaseId) {
		this.phaseId = phaseId;
	}

	public Integer getPercentMeasure() {
		return percentMeasure;
	}

	public void setPercentMeasure(Integer percentMeasure) {
		this.percentMeasure = percentMeasure;
	}

	public String getDeadLine() {
		return deadLine;
	}

	public void setDeadLine(String deadLine) {
		this.deadLine = deadLine;
	}

	public Boolean getFinished() {
		return finished;
	}

	public void setFinished(Boolean finished) {
		this.finished = finished;
	}

	public String getTaskName() {
		return taskName;
	}

	public void setTaskName(String taskName) {
		this.taskName = taskName;
	}
	
	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public Integer getIndex() {
		return index;
	}

	public void setIndex(Integer index) {
		this.index = index;
	}

	@SynchronizeAttributeWithOther(direction = SynchronizeDirection.FROM, value = "createDate")
	public void initCreatedDateFromEntity(Object entity) {
		if (entity != null && entity instanceof Date) {
			Date date = (Date) entity;
			transformCreatedDate(date);
		}
	}
	
	@SynchronizeAttributeWithOther(direction = SynchronizeDirection.FROM, value = "deadLine")
	public void initDeadLine(Object entity){
		if(entity != null && entity instanceof Date){
			Date deadLineDate = (Date) entity;
			deadLine = CalendarUtils.formatDate(deadLineDate, "dd/MM/yyyy");
		}
	}
	
	@SynchronizeAttributeWithOther(direction = SynchronizeDirection.TO, value="deadLine")
	public Date copyDeadLine(){
		if(!StringUtils.isBlank(deadLine)){
			Date date = CalendarUtils.parseDate(deadLine, "dd/MM/yyyy");
			return date;
		}
		
		return new Date();
	}
}
